<?php

/**
 * Description of MySQLDatabase
 *
 * @author Ervinne
 */
class MySQLDatabase implements IDatabase {

    protected $host;
    protected $database;
    protected $username;
    protected $password;
    protected $lastTableUsed;
    protected $autoconnect = false;
    protected $connection;

    public function __construct($host, $database, $username, $password, $autoconnect = false) {
        $this->host = $host;
        $this->database = $database;
        $this->username = $username;
        $this->password = $password;

        $this->autoconnect = $autoconnect;

        if ($this->autoconnect) {
            $this->connect();
        }
    }

    public function table($tableName) {
        $this->lastTableUsed = $tableName;
        //  allow chaining
        return $this;
    }

    public function query($query) {
        return $this->connection->query($query);
    }
    
    public function connect() {
        $this->connection = new PDO(
                "mysql:host={$this->host};"
                . "dbname={$this->database};", $this->username, $this->password);
    }

    public function disconnect() {
        $this->connection = null;
    }

}
